<?php
/**
 * Example of MDB2 Schema dump of an existing Aborior's Simplex database
 * 
 * @category   Database
 * @package    DB_Simplex
 * @subpackage Documentation
 * @author     Philippe Jausions <jausions@php.net>
 * @copyright  2008 by 11abacus/Philippe Jausions
 * @license    http://www.opensources.org/licenses/license-bsd.php BSD license
 * @link       http://pear.11abacus.com/package/DB_Simplex
 */

require_once dirname(__FILE__).'/config.php';
require_once 'DB/Simplex.php';
require_once 'MDB2/Schema.php';

$dsn = array(
    'phptype' => 'simplex',
    'hostspec' => DB_SIMPLEX_EXAMPLE_PATH,
    'database' => 'News',
);

$schema = MDB2_Schema::factory($dsn);

$error    = null;
$filename = dirname(__FILE__).'/schema.xml';
if (PEAR::isError($schema)) {
    $error = $schema;
} else {
    $dump_options = array(
      'output_mode' => 'file',
      'output' => $filename,
      'end_of_line' => "\n"
    );

    $definition = $schema->getDefinitionFromDatabase();
    if (PEAR::isError($definition)) {
        $error = $definition;
    } else {
        $op = $schema->dumpDatabase($definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE);
        if (PEAR::isError($op)) {
            $error = $op;
        }
    }
}

if ($error !== null) {
    echo 'ERROR: ';
    print_r($error);
} else {
    //echo "Done\n";
    readfile($filename);
}

$schema->disconnect();

?>